`
https://leetcode.cn/problems/guess-number-higher-or-lower/
`

/** 
 * Forward declaration of guess API.
 * @param {number} num   your guess
 * @return 	     -1 if num is higher than the picked number
 *			      1 if num is lower than the picked number
 *               otherwise return 0
 * var guess = function(num) {}
 */

/**
 * @param {number} n
 * @return {number}
 */
var guessNumber = function (n) {
  let left = 0, right = n + 1
  while (left + 1 < right) {
    const mid = left + Math.floor((right - left) / 2)
    if (guess(mid) <= 0) {
      right = mid
    } else {
      left = mid
    }
  }
  return right
};